namespace SqlQueryBuilder.Clauses
{
    /// <summary>
    /// Between Clause
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Between<T> : AbstractValueClause, INotClause
    {
        private readonly string field;
        private readonly object minValue;
        private readonly object maxValue;

        /// <summary>
        /// Initializes a new instance of the <see cref="Between&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="minValue">The min value.</param>
        /// <param name="maxValue">The max value.</param>
        public Between(string field, T minValue, T maxValue)
        {
            this.field = field;
            this.maxValue = maxValue;
            this.minValue = minValue;
        }

        /// <summary>
        /// Builds the where clause.
        /// </summary>
        /// <returns></returns>
        public string BuildConditionalClause()
        {
            return CreateClause();
        }

        /// <summary>
        /// Creates the clause.
        /// </summary>
        /// <returns></returns>
        private string CreateClause()
        {
            return string.Format("{0} BETWEEN {1} AND {2}", 
                                 field, 
                                 FormatSQLValue(minValue), 
                                 FormatSQLValue(maxValue));
        }

    }
}